<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      // 改变函数内this指向，js提供了三种方法：call()  apply()  bind()
      // 1. call()方法
      var o = {
        name: "MooN",
      }

      function fn(a, b) {
        console.log(this)
        console.log(a + b)
      }
      // call 第一个可以调用函数 第二个可以改变函数内的this 指向
      fn.call(o, 1, 2)

      // call 的主要作用可以实现继承
      function Father(uname, age, sex) {
        this.uname = uname
        this.age = age
        this.sex = sex
      }

      function Son(uname, age, sex) {
        Father.call(this, uname, age, sex)
      }
      var son = new Son("路飞", 18, "男")
      console.log(son)
    </script>
  </body>
</html>
